<template>
<onekit-page>
<onekit-view onekit-class="container">
	<div is="onekit-template-head" :DATA="`${JSON.stringify({title:'uploadFile'})}`"></div>
	<onekit-view onekit-class="page-body">
		<onekit-view onekit-class="page-section">
			<onekit-view onekit-class="page-body-info">
				<template v-if="imageSrc">
					<onekit-image onekit-class="image" :src="imageSrc" mode="aspectFit"></onekit-image>
				</template>
				<template v-else>
					<onekit-view onekit-class="image-plus image-plus-nb" @click.native="chooseImage">
						<onekit-view onekit-class="image-plus-horizontal"></onekit-view>
						<onekit-view onekit-class="image-plus-vertical"></onekit-view>
					</onekit-view>
					<onekit-view onekit-class="image-plus-text">选择图片</onekit-view>
				</template>
			</onekit-view>
		</onekit-view>
	</onekit-view>
	<div is="onekit-template-foot"></div>
</onekit-view>
</onekit-page></template>
<script>
/* eslint-disable */
import Vue from 'vue';
import onekit_template_0 from '../../../common/head.head.vue';Vue.component('onekit-template-head',onekit_template_0);
import onekit_template_1 from '../../../common/foot.foot.vue';Vue.component('onekit-template-foot',onekit_template_1);
const ONEKIT_JSON= {
  "navigationBarTitleText": "上传文件",
  "usingComponents": {
    
  }
};
const ONEKIT_SJS = {
};
import wx from '../../../../weixin2vue/wx.js';
import Macro from '../../../../weixin2vue/Macro.js';
const {getApp,getCurrentPages} = Macro;
import Page from '../../../../weixin2vue/OnekitPage.js';
import Component from '../../../../weixin2vue/OnekitComponent.js';
export default Page(ONEKIT_JSON,["imageSrc"],ONEKIT_SJS,{
    "onShareAppMessage"(){
      return {
        "title":'上传文件',
        "path":'packageAPI/pages/upload-file/upload-file'
};
    },
    "chooseImage"(){
      const self = this;
      wx.chooseImage({
        "count":1,
        "sizeType":[
          'compressed'
        ],
        "sourceType":[
          'album'
        ],
        "success"(res){
          console.log('chooseImage success, temp path is',res.tempFilePaths[0]);
          const imageSrc = res.tempFilePaths[0];
          wx.cloud.uploadFile({
            "cloudPath":'example.png',
            "filePath":imageSrc,
            "config":{
                "env":'release-b86096'
},
            "success":(res)=>{
              console.log(res.fileID);
              console.log('uploadImage success, res is:',res);
              wx.showToast({
                  "title":'上传成功',
                  "icon":'success',
                  "duration":1000
});
              self.setData({
                  imageSrc,
                  "fileID":res.fileID
});
            },
            "fail"({errMsg}){
              console.log('uploadImage fail, errMsg is',errMsg);
            }
});
        },
        "fail":(res)=>{
          wx.showToast({
              "icon":'none',
              "title":'上传失败'
});
          console.log('uploadImage fail, errMsg is',res.errMsg);
        }
});
    },
    "onUnload"(){
      if(this.data.fileID)
      {
        wx.cloud.deleteFile({
            "fileList":[
              this.data.fileID
            ]
});
      };
    }
});

</script>
<style 
 lang="css">
.image {
  width: 100% ;
  height: 330px ;
}
.page-body-info {
  display: flex ;
  box-sizing: border-box ;
  padding: 15px ;
  height: 410px ;
  border-top: 1px solid var(--weui-FG-3) ;
  border-bottom: 1px solid var(--weui-FG-3) ;
  align-items: center ;
  justify-content: center ;
}
</style>